package com.dhcc.rabbitmq.base.producer;

import com.google.gson.Gson;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 
* <p>标题: HelloSender.java</p>
* <p>业务描述:消息发送者（生产者）</p>
* <p>公司:东华软件股份公司</p>
* <p>版权:dhcc2013</p>
* @author 胡凯
* @date 2019年7月29日
* @version V1.0
 */
@Component
public class HelloSender {

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void send1(Object obj){
//        String context = "hello"+new Date();
        Gson gson = new Gson();
        System.out.println("Sender1 : "+gson.toJson(obj));
        this.amqpTemplate.convertAndSend("hello",gson.toJson(obj));
    }

    public void send2(Object obj){
//        String context = "hello"+new Date();
        Gson gson = new Gson();
        System.out.println("Sender2 : "+gson.toJson(obj));
        this.amqpTemplate.convertAndSend("hello",gson.toJson(obj));
    }
    
    public void send(int i) {
        String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());//24小时制
        String context = "hello " + i + " " + date;
        System.out.println("Sender : " + context);
        //简单对列的情况下routingKey即为Q名
        this.amqpTemplate.convertAndSend("hello", context);
    }

}
